package name;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ChstClientReadThread extends  Thread {
    private Socket socket;
    public ChstClientReadThread(Socket socket){
        this.socket=socket;
    }

    @Override
    public void run() {
        final DataInputStream dip;
        try {
            InputStream in = socket.getInputStream();
            dip = new DataInputStream(in);
            while (true) {
                try {
                    String s = dip.readUTF();
                    System.out.println(s);
                } catch (IOException e) {
                    System.out.println("自己已经下线");
                    System.out.println(socket.getRemoteSocketAddress());
                    ChatSever.oneline.remove(socket);
                    dip.close();
                    socket.close();
                    break;
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
